package org.learn.test;

public class MethodExercise02 {
    public static void main(String[] args){
    Person1 P= new Person1();
    P.age = 18;
    P.name = "李明";
    MyTools tools = new MyTools();
    Person1 P2 = tools.copyPerson1(P);
    //到此p和p2是两个独立的对象；属性相同；
    System.out.println("p的属性 age=" + P.age + "名字=" + P.name);
    System.out.println("p2的属性 age=" + P2.age + "名字=" + P2.name);
    }
}


class Person1{
    String name;
    int age;
}
class MyTools{
    public Person1 copyPerson1(Person1 p){
        //创建一个新的对象
        Person1 P2 = new Person1();
        P2.name = p.name;
        P2.age = p.age;
        return P2;
    }
}